const mongoose = require("./index");

const departmentSchema = new mongoose.Schema(
	{
		// 上级部门
		pid: {
			type: mongoose.Schema.Types.ObjectId,
		},
		// 部门标识
		key: {
			type: String,
			required: [true, "部门标识不能为空"],
			unique: [true, "部门标识不能重复"],
		},
		// 部门名称
		name: {
			type: String,
			required: [true, "部门名称不能为空"],
			unique: [true, "部门名称不能重复"],
		},
		// 排序
		sort: {
			type: Number,
			required: [true, "排序不能为空"],
		},
		// 状态
		status: {
			type: String,
			enum: ["disable", "enable"],
			default: "enable",
		},
	},
	{ timestamps: true }
);

module.exports = mongoose.model("department", departmentSchema);
